﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwObracunTraziProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwObracunTraziProviderBaseCore : EntityViewProviderBase<VwObracunTrazi>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwObracunTrazi&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwObracunTrazi&gt;"/></returns>
		protected static VList&lt;VwObracunTrazi&gt; Fill(DataSet dataSet, VList<VwObracunTrazi> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwObracunTrazi>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwObracunTrazi&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwObracunTrazi>"/></returns>
		protected static VList&lt;VwObracunTrazi&gt; Fill(DataTable dataTable, VList<VwObracunTrazi> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwObracunTrazi c = new VwObracunTrazi();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.DatumOd = (Convert.IsDBNull(row["DatumOd"]))?DateTime.MinValue:(System.DateTime)row["DatumOd"];
					c.DatumDo = (Convert.IsDBNull(row["DatumDo"]))?DateTime.MinValue:(System.DateTime)row["DatumDo"];
					c.VrstaUplateRSMSifra = (Convert.IsDBNull(row["VrstaUplateRSMSifra"]))?string.Empty:(System.String)row["VrstaUplateRSMSifra"];
					c.VrstaUplateRSMNaziv = (Convert.IsDBNull(row["VrstaUplateRSMNaziv"]))?string.Empty:(System.String)row["VrstaUplateRSMNaziv"];
					c.IdentifikatorIDObrascaSifra = (Convert.IsDBNull(row["IdentifikatorIDObrascaSifra"]))?string.Empty:(System.String)row["IdentifikatorIDObrascaSifra"];
					c.IdentifikatorIDObrasacNaziv = (Convert.IsDBNull(row["IdentifikatorIDObrasacNaziv"]))?string.Empty:(System.String)row["IdentifikatorIDObrasacNaziv"];
					c.RedniBrojUGodini = (Convert.IsDBNull(row["RedniBrojUGodini"]))?(int)0:(System.Int32)row["RedniBrojUGodini"];
					c.FondSati = (Convert.IsDBNull(row["FondSati"]))?0.0F:(System.Single)row["FondSati"];
					c.BrutoOsnovica = (Convert.IsDBNull(row["BrutoOsnovica"]))?0:(System.Decimal)row["BrutoOsnovica"];
					c.BrOsoba = (Convert.IsDBNull(row["BrOsoba"]))?(int)0:(System.Int32?)row["BrOsoba"];
					c.SumBruto = (Convert.IsDBNull(row["SumBruto"]))?0:(System.Decimal?)row["SumBruto"];
					c.SumNeto = (Convert.IsDBNull(row["SumNeto"]))?0:(System.Decimal?)row["SumNeto"];
					c.SumBruto2 = (Convert.IsDBNull(row["SumBruto2"]))?0:(System.Decimal?)row["SumBruto2"];
					c.AvgBruto = (Convert.IsDBNull(row["AvgBruto"]))?0:(System.Decimal?)row["AvgBruto"];
					c.AvgNeto = (Convert.IsDBNull(row["AvgNeto"]))?0:(System.Decimal?)row["AvgNeto"];
					c.AvgBruto2 = (Convert.IsDBNull(row["AvgBruto2"]))?0:(System.Decimal?)row["AvgBruto2"];
					c.Status = (Convert.IsDBNull(row["Status"]))?(int)0:(System.Int32)row["Status"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwObracunTrazi&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwObracunTrazi&gt;"/></returns>
		protected VList<VwObracunTrazi> Fill(IDataReader reader, VList<VwObracunTrazi> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwObracunTrazi entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwObracunTrazi>("VwObracunTrazi",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwObracunTrazi();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.DatumOd = (System.DateTime)reader["DatumOd"];
					//entity.DatumOd = (Convert.IsDBNull(reader["DatumOd"]))?DateTime.MinValue:(System.DateTime)reader["DatumOd"];
					entity.DatumDo = (System.DateTime)reader["DatumDo"];
					//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime)reader["DatumDo"];
					entity.VrstaUplateRSMSifra = reader.IsDBNull(reader.GetOrdinal("VrstaUplateRSMSifra")) ? null : (System.String)reader["VrstaUplateRSMSifra"];
					//entity.VrstaUplateRSMSifra = (Convert.IsDBNull(reader["VrstaUplateRSMSifra"]))?string.Empty:(System.String)reader["VrstaUplateRSMSifra"];
					entity.VrstaUplateRSMNaziv = reader.IsDBNull(reader.GetOrdinal("VrstaUplateRSMNaziv")) ? null : (System.String)reader["VrstaUplateRSMNaziv"];
					//entity.VrstaUplateRSMNaziv = (Convert.IsDBNull(reader["VrstaUplateRSMNaziv"]))?string.Empty:(System.String)reader["VrstaUplateRSMNaziv"];
					entity.IdentifikatorIDObrascaSifra = reader.IsDBNull(reader.GetOrdinal("IdentifikatorIDObrascaSifra")) ? null : (System.String)reader["IdentifikatorIDObrascaSifra"];
					//entity.IdentifikatorIDObrascaSifra = (Convert.IsDBNull(reader["IdentifikatorIDObrascaSifra"]))?string.Empty:(System.String)reader["IdentifikatorIDObrascaSifra"];
					entity.IdentifikatorIDObrasacNaziv = reader.IsDBNull(reader.GetOrdinal("IdentifikatorIDObrasacNaziv")) ? null : (System.String)reader["IdentifikatorIDObrasacNaziv"];
					//entity.IdentifikatorIDObrasacNaziv = (Convert.IsDBNull(reader["IdentifikatorIDObrasacNaziv"]))?string.Empty:(System.String)reader["IdentifikatorIDObrasacNaziv"];
					entity.RedniBrojUGodini = (System.Int32)reader["RedniBrojUGodini"];
					//entity.RedniBrojUGodini = (Convert.IsDBNull(reader["RedniBrojUGodini"]))?(int)0:(System.Int32)reader["RedniBrojUGodini"];
					entity.FondSati = (System.Single)reader["FondSati"];
					//entity.FondSati = (Convert.IsDBNull(reader["FondSati"]))?0.0F:(System.Single)reader["FondSati"];
					entity.BrutoOsnovica = (System.Decimal)reader["BrutoOsnovica"];
					//entity.BrutoOsnovica = (Convert.IsDBNull(reader["BrutoOsnovica"]))?0:(System.Decimal)reader["BrutoOsnovica"];
					entity.BrOsoba = reader.IsDBNull(reader.GetOrdinal("BrOsoba")) ? null : (System.Int32?)reader["BrOsoba"];
					//entity.BrOsoba = (Convert.IsDBNull(reader["BrOsoba"]))?(int)0:(System.Int32?)reader["BrOsoba"];
					entity.SumBruto = reader.IsDBNull(reader.GetOrdinal("SumBruto")) ? null : (System.Decimal?)reader["SumBruto"];
					//entity.SumBruto = (Convert.IsDBNull(reader["SumBruto"]))?0:(System.Decimal?)reader["SumBruto"];
					entity.SumNeto = reader.IsDBNull(reader.GetOrdinal("SumNeto")) ? null : (System.Decimal?)reader["SumNeto"];
					//entity.SumNeto = (Convert.IsDBNull(reader["SumNeto"]))?0:(System.Decimal?)reader["SumNeto"];
					entity.SumBruto2 = reader.IsDBNull(reader.GetOrdinal("SumBruto2")) ? null : (System.Decimal?)reader["SumBruto2"];
					//entity.SumBruto2 = (Convert.IsDBNull(reader["SumBruto2"]))?0:(System.Decimal?)reader["SumBruto2"];
					entity.AvgBruto = reader.IsDBNull(reader.GetOrdinal("AvgBruto")) ? null : (System.Decimal?)reader["AvgBruto"];
					//entity.AvgBruto = (Convert.IsDBNull(reader["AvgBruto"]))?0:(System.Decimal?)reader["AvgBruto"];
					entity.AvgNeto = reader.IsDBNull(reader.GetOrdinal("AvgNeto")) ? null : (System.Decimal?)reader["AvgNeto"];
					//entity.AvgNeto = (Convert.IsDBNull(reader["AvgNeto"]))?0:(System.Decimal?)reader["AvgNeto"];
					entity.AvgBruto2 = reader.IsDBNull(reader.GetOrdinal("AvgBruto2")) ? null : (System.Decimal?)reader["AvgBruto2"];
					//entity.AvgBruto2 = (Convert.IsDBNull(reader["AvgBruto2"]))?0:(System.Decimal?)reader["AvgBruto2"];
					entity.Status = (System.Int32)reader["Status"];
					//entity.Status = (Convert.IsDBNull(reader["Status"]))?(int)0:(System.Int32)reader["Status"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwObracunTrazi"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunTrazi"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwObracunTrazi entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.DatumOd = (System.DateTime)reader["DatumOd"];
			//entity.DatumOd = (Convert.IsDBNull(reader["DatumOd"]))?DateTime.MinValue:(System.DateTime)reader["DatumOd"];
			entity.DatumDo = (System.DateTime)reader["DatumDo"];
			//entity.DatumDo = (Convert.IsDBNull(reader["DatumDo"]))?DateTime.MinValue:(System.DateTime)reader["DatumDo"];
			entity.VrstaUplateRSMSifra = reader.IsDBNull(reader.GetOrdinal("VrstaUplateRSMSifra")) ? null : (System.String)reader["VrstaUplateRSMSifra"];
			//entity.VrstaUplateRSMSifra = (Convert.IsDBNull(reader["VrstaUplateRSMSifra"]))?string.Empty:(System.String)reader["VrstaUplateRSMSifra"];
			entity.VrstaUplateRSMNaziv = reader.IsDBNull(reader.GetOrdinal("VrstaUplateRSMNaziv")) ? null : (System.String)reader["VrstaUplateRSMNaziv"];
			//entity.VrstaUplateRSMNaziv = (Convert.IsDBNull(reader["VrstaUplateRSMNaziv"]))?string.Empty:(System.String)reader["VrstaUplateRSMNaziv"];
			entity.IdentifikatorIDObrascaSifra = reader.IsDBNull(reader.GetOrdinal("IdentifikatorIDObrascaSifra")) ? null : (System.String)reader["IdentifikatorIDObrascaSifra"];
			//entity.IdentifikatorIDObrascaSifra = (Convert.IsDBNull(reader["IdentifikatorIDObrascaSifra"]))?string.Empty:(System.String)reader["IdentifikatorIDObrascaSifra"];
			entity.IdentifikatorIDObrasacNaziv = reader.IsDBNull(reader.GetOrdinal("IdentifikatorIDObrasacNaziv")) ? null : (System.String)reader["IdentifikatorIDObrasacNaziv"];
			//entity.IdentifikatorIDObrasacNaziv = (Convert.IsDBNull(reader["IdentifikatorIDObrasacNaziv"]))?string.Empty:(System.String)reader["IdentifikatorIDObrasacNaziv"];
			entity.RedniBrojUGodini = (System.Int32)reader["RedniBrojUGodini"];
			//entity.RedniBrojUGodini = (Convert.IsDBNull(reader["RedniBrojUGodini"]))?(int)0:(System.Int32)reader["RedniBrojUGodini"];
			entity.FondSati = (System.Single)reader["FondSati"];
			//entity.FondSati = (Convert.IsDBNull(reader["FondSati"]))?0.0F:(System.Single)reader["FondSati"];
			entity.BrutoOsnovica = (System.Decimal)reader["BrutoOsnovica"];
			//entity.BrutoOsnovica = (Convert.IsDBNull(reader["BrutoOsnovica"]))?0:(System.Decimal)reader["BrutoOsnovica"];
			entity.BrOsoba = reader.IsDBNull(reader.GetOrdinal("BrOsoba")) ? null : (System.Int32?)reader["BrOsoba"];
			//entity.BrOsoba = (Convert.IsDBNull(reader["BrOsoba"]))?(int)0:(System.Int32?)reader["BrOsoba"];
			entity.SumBruto = reader.IsDBNull(reader.GetOrdinal("SumBruto")) ? null : (System.Decimal?)reader["SumBruto"];
			//entity.SumBruto = (Convert.IsDBNull(reader["SumBruto"]))?0:(System.Decimal?)reader["SumBruto"];
			entity.SumNeto = reader.IsDBNull(reader.GetOrdinal("SumNeto")) ? null : (System.Decimal?)reader["SumNeto"];
			//entity.SumNeto = (Convert.IsDBNull(reader["SumNeto"]))?0:(System.Decimal?)reader["SumNeto"];
			entity.SumBruto2 = reader.IsDBNull(reader.GetOrdinal("SumBruto2")) ? null : (System.Decimal?)reader["SumBruto2"];
			//entity.SumBruto2 = (Convert.IsDBNull(reader["SumBruto2"]))?0:(System.Decimal?)reader["SumBruto2"];
			entity.AvgBruto = reader.IsDBNull(reader.GetOrdinal("AvgBruto")) ? null : (System.Decimal?)reader["AvgBruto"];
			//entity.AvgBruto = (Convert.IsDBNull(reader["AvgBruto"]))?0:(System.Decimal?)reader["AvgBruto"];
			entity.AvgNeto = reader.IsDBNull(reader.GetOrdinal("AvgNeto")) ? null : (System.Decimal?)reader["AvgNeto"];
			//entity.AvgNeto = (Convert.IsDBNull(reader["AvgNeto"]))?0:(System.Decimal?)reader["AvgNeto"];
			entity.AvgBruto2 = reader.IsDBNull(reader.GetOrdinal("AvgBruto2")) ? null : (System.Decimal?)reader["AvgBruto2"];
			//entity.AvgBruto2 = (Convert.IsDBNull(reader["AvgBruto2"]))?0:(System.Decimal?)reader["AvgBruto2"];
			entity.Status = (System.Int32)reader["Status"];
			//entity.Status = (Convert.IsDBNull(reader["Status"]))?(int)0:(System.Int32)reader["Status"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwObracunTrazi"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwObracunTrazi"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwObracunTrazi entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.DatumOd = (Convert.IsDBNull(dataRow["DatumOd"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumOd"];
			entity.DatumDo = (Convert.IsDBNull(dataRow["DatumDo"]))?DateTime.MinValue:(System.DateTime)dataRow["DatumDo"];
			entity.VrstaUplateRSMSifra = (Convert.IsDBNull(dataRow["VrstaUplateRSMSifra"]))?string.Empty:(System.String)dataRow["VrstaUplateRSMSifra"];
			entity.VrstaUplateRSMNaziv = (Convert.IsDBNull(dataRow["VrstaUplateRSMNaziv"]))?string.Empty:(System.String)dataRow["VrstaUplateRSMNaziv"];
			entity.IdentifikatorIDObrascaSifra = (Convert.IsDBNull(dataRow["IdentifikatorIDObrascaSifra"]))?string.Empty:(System.String)dataRow["IdentifikatorIDObrascaSifra"];
			entity.IdentifikatorIDObrasacNaziv = (Convert.IsDBNull(dataRow["IdentifikatorIDObrasacNaziv"]))?string.Empty:(System.String)dataRow["IdentifikatorIDObrasacNaziv"];
			entity.RedniBrojUGodini = (Convert.IsDBNull(dataRow["RedniBrojUGodini"]))?(int)0:(System.Int32)dataRow["RedniBrojUGodini"];
			entity.FondSati = (Convert.IsDBNull(dataRow["FondSati"]))?0.0F:(System.Single)dataRow["FondSati"];
			entity.BrutoOsnovica = (Convert.IsDBNull(dataRow["BrutoOsnovica"]))?0:(System.Decimal)dataRow["BrutoOsnovica"];
			entity.BrOsoba = (Convert.IsDBNull(dataRow["BrOsoba"]))?(int)0:(System.Int32?)dataRow["BrOsoba"];
			entity.SumBruto = (Convert.IsDBNull(dataRow["SumBruto"]))?0:(System.Decimal?)dataRow["SumBruto"];
			entity.SumNeto = (Convert.IsDBNull(dataRow["SumNeto"]))?0:(System.Decimal?)dataRow["SumNeto"];
			entity.SumBruto2 = (Convert.IsDBNull(dataRow["SumBruto2"]))?0:(System.Decimal?)dataRow["SumBruto2"];
			entity.AvgBruto = (Convert.IsDBNull(dataRow["AvgBruto"]))?0:(System.Decimal?)dataRow["AvgBruto"];
			entity.AvgNeto = (Convert.IsDBNull(dataRow["AvgNeto"]))?0:(System.Decimal?)dataRow["AvgNeto"];
			entity.AvgBruto2 = (Convert.IsDBNull(dataRow["AvgBruto2"]))?0:(System.Decimal?)dataRow["AvgBruto2"];
			entity.Status = (Convert.IsDBNull(dataRow["Status"]))?(int)0:(System.Int32)dataRow["Status"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwObracunTraziFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunTrazi"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunTraziFilterBuilder : SqlFilterBuilder<VwObracunTraziColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunTraziFilterBuilder class.
		/// </summary>
		public VwObracunTraziFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTraziFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunTraziFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTraziFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunTraziFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunTraziFilterBuilder

	#region VwObracunTraziParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwObracunTrazi"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwObracunTraziParameterBuilder : ParameterizedSqlFilterBuilder<VwObracunTraziColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwObracunTraziParameterBuilder class.
		/// </summary>
		public VwObracunTraziParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTraziParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwObracunTraziParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwObracunTraziParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwObracunTraziParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwObracunTraziParameterBuilder
} // end namespace
